package com.aaa.lib_compiler.my;

import javax.lang.model.element.Element;
import javax.lang.model.element.Name;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;

public class MyAnnotatedElement {
    Element element;
    Name qualifiedClassName;
    Name simpleClassName;
    Name elementName;
    TypeMirror elementType;

    public MyAnnotatedElement(Element element) {
        this.element = element;
        elementName = element.getSimpleName();
        elementType = element.asType();
        simpleClassName = element.getEnclosingElement().getSimpleName();
        qualifiedClassName = ((TypeElement) element.getEnclosingElement()).getQualifiedName();
    }

    public Name getQualifiedClassName() {
        return qualifiedClassName;
    }

    public Name getSimpleClassName() {
        return simpleClassName;
    }

    public Name getElementName() {
        return elementName;
    }

    public TypeMirror getElementType() {
        return elementType;
    }

    public Element getElement() {
        return element;
    }

    public String getPackageName() {
        return qualifiedClassName.toString().substring(0, qualifiedClassName.toString().lastIndexOf("."));
    }

    @Override
    public String toString() {
        return "Qualified class name : " + qualifiedClassName.toString() + "\n"
                + "Simple class name : " + simpleClassName.toString() + "\n"
                + "Element name : " + elementName.toString() + "\n"
                + "Element type : " + elementType.toString() + "\n";
    }
}
